/*
import com.swagger.demo.util.BeanUtilsEx;
import com.swagger.demo.util.DateUtil;
import com.swagger.demo.util.Export;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.*;

*/
/**
 * creat by
 *
 * @author heyang
 * @date 2020/9/10 15:23
 *//*

public class ExportUtils {

    private Logger logger = LoggerFactory.getLogger(getClass());

    //存放地址
    private final static String bucketName = "gxs-bucket";


    // 工作薄
    private SXSSFWorkbook wb = new SXSSFWorkbook(100);
    private Sheet sheet;

    // 导出数据的必要条件
    private final Class<?> clazz;
    private final String[] fields;
    private final String[] headers;
    private final String exportDir;

    public ExportUtils(Class<?> clazz, String[] fields, String[] headers, String exportDir) {
        this.clazz = clazz;
        this.fields = fields;
        this.headers = headers;
        this.exportDir = exportDir;
        this.sheet = this.createSheet();
    }

    public ExportUtils(Class<?> clazz, String[] fields, String[] headers, String exportDir, String[] condition) {
        this.clazz = clazz;
        this.fields = fields;
        this.headers = headers;
        this.exportDir = exportDir;
        this.sheet = this.createSheetByCondition(condition);
    }

    public ExportUtils(Class<?> clazz, String[] fields, String[] headers, String exportDir, String sheetName) {
        this.clazz = clazz;
        this.fields = fields;
        this.headers = headers;
        this.exportDir = exportDir;
        this.sheet = this.createSheet(sheetName);
    }

    public ExportUtils(Class<?> clazz, String exportDir) {
        this.clazz = clazz;
        this.fields = "".split("");
        this.headers = "".split("");
        this.exportDir = exportDir;
    }

    // 数据转换的映射关系
    private Map<String, String> map = new HashMap<String, String>(1);

    */
/**
     * TODO
     * 设置映射关系
     *
     * @param field
     * @param source
     * @param target
     *//*

    public void setMapping(String field, String source, String target) {
        if (null == field || null == source || null == target) {
            return;
        }
        map.put(field + source, target);
    }

    */
/**
     * TODO
     * 获取映射的值
     *
     * @param field
     * @param source
     * @return
     *//*

    private Object getMapping(String field, Object source) {
        if (map.isEmpty()) {
            return source;
        }
        if (map.containsKey(field + source)) {
            return map.get(field + source);
        }
        return source;
    }

    */
/**
     * TODO
     * 创建SHEET
     *
     * @return
     *//*

    private Sheet createSheet() {
        // SHEET
        Sheet sheet = wb.createSheet();
        sheet.setDefaultColumnWidth(20);
        sheet.setDefaultRowHeightInPoints(16);
        // FONT
        Font font = wb.createFont();
        font.setBold(true);
        // CELL STYLE
        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        // 产生表格标题行
        Cell cell = null;
        Row row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(headers[i]);
        }
        return sheet;
    }

    */
/**
     * TODO
     * 创建SHEET
     *
     * @return
     *//*

    private Sheet createSheetByCondition(String[] condition) {
        // SHEET
        Sheet sheet = wb.createSheet();
        sheet.setDefaultColumnWidth(20);
        sheet.setDefaultRowHeightInPoints(16);
        // FONT
        Font font = wb.createFont();
        font.setBold(true);
        // CELL STYLE
        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        Cell cell0 = null;
        Row row0 = sheet.createRow(0);
        for (int i = 0; i < condition.length; i++) {
            cell0 = row0.createCell(i);
            cell0.setCellStyle(style);
            cell0.setCellValue(condition[i]);
        }
        // 产生表格标题行
        Cell cell = null;
        Row row = sheet.createRow(1);
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(headers[i]);
        }
        return sheet;
    }

    */
/**
     * TODO
     * 创建SHEET
     *
     * @return
     *//*

    private Sheet createSheet(String sheetName) {
        // SHEET
        Sheet sheet = wb.createSheet(sheetName);
        sheet.setDefaultColumnWidth(20);
        sheet.setDefaultRowHeightInPoints(16);
        // FONT
        Font font = wb.createFont();
        font.setBold(true);
        // CELL STYLE
        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        // 产生表格标题行
        Cell cell = null;
        Row row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(headers[i]);
        }
        return sheet;
    }

    */
/**
     * 自定义表头创建SHEET
     *
     * @return
     *//*

    private Sheet createSheet(String[] headers) {
        // SHEET
        Sheet sheet = wb.createSheet();
        sheet.setDefaultColumnWidth(20);
        sheet.setDefaultRowHeightInPoints(16);
        // FONT
        Font font = wb.createFont();
        font.setBold(true);
        // CELL STYLE
        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        // 产生表格标题行
        Cell cell = null;
        Row row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(headers[i]);
        }
        return sheet;
    }

    */
/**
     * 自定义表头创建SHEET
     *
     * @return
     *//*

    private Sheet createSheet(String[] headers, String sheetName) {
        // SHEET
        Sheet sheet = wb.createSheet(sheetName);
        sheet.setDefaultColumnWidth(20);
        sheet.setDefaultRowHeightInPoints(16);
        // FONT
        Font font = wb.createFont();
        font.setBold(true);
        // CELL STYLE
        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        // 产生表格标题行
        Cell cell = null;
        Row row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(headers[i]);
        }
        return sheet;
    }

    */
/**
     * TODO
     * 导出数据
     *
     * @param list
     * @return
     *//*

    public void convert(List<?> list) {
        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        // 用于格式化单元格的数据
        DataFormat format = wb.createDataFormat();

        Map<String, Object> map;
        int rowIndex = sheet.getLastRowNum();
        for (Object o : list) {
            map = BeanUtilsEx.describe(o);

            // 每五十万条分一个sheet表
            rowIndex++;
            if (rowIndex > 500001) {
                sheet = this.createSheet();
                rowIndex = 1;
            }

            Row row = sheet.createRow(rowIndex);
            for (int i = 0; i < fields.length; i++) {
                Cell cell = row.createCell(i);
                cell.setCellStyle(style);
                cell.setCellType(1);

                String key = fields[i];
                if (!map.containsKey(key)) {
                    continue;
                }

                Object value = map.get(key);
                if (null == value) {
                    cell.setCellValue("");
                    continue;
                }

                // 判断是否是时间字段
                if (key.toLowerCase().endsWith("time") && value instanceof Long) {
                    // 如果时间为0 则不显示
                    if (Long.valueOf(value.toString()) == 0) {
                        cell.setCellValue("");
                        continue;
                    }
                    // 将long时间 转换为 yyyy-MM-dd HH:mm:ss
                    value = DateUtil.getDateTime(Long.valueOf(value.toString()));
                }
                // 如果是导出数量 则转为数字格式
                if (key.toLowerCase().contains("count") && value instanceof Integer) {
                    cell.setCellType(0);
                    cell.setCellValue(((Integer) value).intValue());
//                    style.setDataFormat(format.getFormat("#,#0"));//设置单元类型
                    continue;
                }

                String result = this.getValue(key, value, o);
                if (result.length() > 255) {
                    cell.setCellValue(result.substring(0, 250) + " ... ");
                } else {
                    cell.setCellValue(result);
                }
            }
        }
    }

    */
/**
     * TODO
     * 获取对象中的值
     *
     * @param key
     * @param value
     * @param o
     *//*

    private String getValue(String key, Object value, Object o) {
        try {
            Field filed = clazz.getDeclaredField(key);
            Export export = filed.getAnnotation(Export.class);
            if (null == export) {
                return this.getMapping(key, value).toString();
            }

            // 是否是可迭代的对象
            if (export.iterable() && value instanceof Collection) {
                Collection<?> col = (Collection<?>) value;
                StringBuilder sb = new StringBuilder();
                for (Object c : col) {
                    if (sb.length() > 0) {
                        sb.append(" ; ");
                    }
                    sb.append(this.getValue(export.fields(), false, c, null));
                }
                return sb.toString();
            }

            return this.getValue(export.fields(), export.oneself(), value, o);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    */
/**
     * 根据注解获取对象中的值
     *
     * @param value
     * @param o
     * @param fields
     * @param oneself
     * @return
     *//*

    private String getValue(String[] fields, boolean oneself, Object value, Object o) {
        Object obj = null;
        StringBuilder sb = new StringBuilder();

        for (int k = 0; k < fields.length; k++) {
            if (sb.length() > 0) {
                sb.append(" / ");
            }

            if (oneself) {
                obj = this.invoke(fields[k], clazz, o);// 来自当前对象
            } else {
                obj = this.invoke(fields[k], value.getClass(), value);// 来自关联表
            }

            if (null == obj) {
                sb.append(" ");
            } else {
                sb.append(this.getMapping(fields[k], obj));
            }
        }

        return sb.toString();
    }

    */
/**
     * TODO
     * 调用Get方法获取值
     *
     * @param o
     * @param property
     * @param c
     * @return
     *//*

    private Object invoke(String property, Class<?> c, Object o) {
        try {
            PropertyDescriptor pd = new PropertyDescriptor(property, c);
            return pd.getReadMethod().invoke(o);
        } catch (Exception e) {
            logger.error("", e);
            return null;
        }
    }

    */
/**
     * TODO
     * 生成Excel文件
     *
     * @return
     *//*

//    public String export() {
//        File excelFile = null;
//        try {
//            excelFile = exportFile();
//            // 压缩excel文件并返回
//            long time = new Date().getTime();
//            ZipCompressor.compress(excelFile, new File(this.exportDir, time + ".zip"));
//            // 返回绝对值路径
//            return this.exportDir + time + ".zip";
//        } catch (Exception e) {
//            logger.error("====生成Excel文件===>", e);
//            return null;
//        } finally {
//            if (excelFile != null && excelFile.exists()) {
//                excelFile.delete();
//            }
//        }
//    }

//    public String asynExport(List<?> list, String filePath, AliyunUpload aliyunUpload) {
//        File file = null;
//        String path = null;
//        try {
//            // 导出数据
//            convert(list);
//            // 生成Excel表
//            file = exportFile();
//            InputStream inputStream = new FileInputStream(file);
//            // 上传Excel至阿里云
//            filePath = aliyunUpload.createFolder(bucketName, filePath);
//            path = aliyunUpload.uploadFile(bucketName, "xls", filePath, inputStream);
//            inputStream.close();
//        } catch (Exception e) {
//            logger.error("", e);
//        } finally {
//            if (file != null) {
//                file.delete();
//            }
//        }
//        return path;
//    }

//    public String asynExportOption(List<?> list, List<Map<String, String>> summaryList, String filePath, AliyunUpload aliyunUpload) {
//        File file = null;
//        String path = null;
//        try {
//            // 导出数据
//            convertOption(list, summaryList);
//            // 生成Excel表
//            file = exportFile();
//            InputStream inputStream = new FileInputStream(file);
//            // 上传Excel至阿里云
//            filePath = aliyunUpload.createFolder(bucketName, filePath);
//            path = aliyunUpload.uploadFile(bucketName, "xls", filePath, inputStream);
//            inputStream.close();
//        } catch (Exception e) {
//            logger.error("", e);
//        } finally {
//            if (file != null) {
//                file.delete();
//            }
//        }
//        return path;
//    }

//    public String asynExportTeam(List<Map<String, List<Map<String, Object>>>> list, String filePath, AliyunUpload aliyunUpload) {
//        File file = null;
//        String path = null;
//        try {
//            // 导出数据
//            convertTeam(list);
//            // 生成Excel表
//            file = exportFile();
//            InputStream inputStream = new FileInputStream(file);
//            // 上传Excel至阿里云
//            filePath = aliyunUpload.createFolder(bucketName, filePath);
//            path = aliyunUpload.uploadFile(bucketName, "xls", filePath, inputStream);
//            inputStream.close();
//        } catch (Exception e) {
//            logger.error("", e);
//        } finally {
//            if (file != null) {
//                file.delete();
//            }
//        }
//        return path;
//    }

//    public String saveExportFile(List<net.sf.json.JSONObject> list, String fileName) {
//        File file = null;
//        String path = null;
//        try {
//            // 导出数据
//            convertExcel(list);
//            // 生成Excel表
//            file = exportFile();
//            InputStream inputStream = new FileInputStream(file);
//            // 上传Excel至阿里云
//            FileOutputStream fos = new FileOutputStream(fileName);
//            byte[] b = new byte[1024];
//            while ((inputStream.read(b)) != -1) {
//                fos.write(b);// 写入数据
//            }
//            inputStream.close();
//            fos.close();// 保存数据
//        } catch (Exception e) {
//            logger.error("", e);
//        } finally {
//            if (file != null) {
//                file.delete();
//            }
//        }
//        return path;
//    }

//    private void convertExcel(List<net.sf.json.JSONObject> res) throws Exception {
//        //创建样式对象
//        CellStyle style = wb.createCellStyle();
//        //设置样式对齐方式：水平\垂直居中
//        style.setAlignment(CellStyle.ALIGN_CENTER);
//        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
//        int rowIndex = sheet.getLastRowNum();
//        Map<String, net.sf.json.JSONObject> map = new HashMap();
//        for (int j = 0; j < res.size(); j++) {
//            rowIndex++;
//            Row row = sheet.createRow(rowIndex);
//            net.sf.json.JSONObject val = res.get(j);
//            String orderNo = val.get("orderNo").toString();
//            Cell cell = row.createCell(0);
//            cell.setCellStyle(style);
//            cell.setCellType(Cell.CELL_TYPE_STRING);
//            cell.setCellValue(orderNo);
//
//            String orderTime = val.get("orderTime").toString();
//            Cell cell1 = row.createCell(1);
//            cell1.setCellStyle(style);
//            cell1.setCellType(Cell.CELL_TYPE_STRING);
//            cell1.setCellValue(orderTime);
//
//            String orderFinalTime = val.get("orderFinalTime").toString();
//            Cell cell2 = row.createCell(2);
//            cell2.setCellStyle(style);
//            cell2.setCellType(Cell.CELL_TYPE_STRING);
//            cell2.setCellValue(orderFinalTime);
//
//
//            String goodsName = val.get("goodsName").toString();
//            Cell cell3 = row.createCell(3);
//            cell3.setCellStyle(style);
//            cell3.setCellType(Cell.CELL_TYPE_STRING);
//            cell3.setCellValue(goodsName);
//
//            String orderPrice = val.get("orderPrice").toString();
//            Cell cell4 = row.createCell(4);
//            cell4.setCellStyle(style);
//            cell4.setCellType(Cell.CELL_TYPE_STRING);
//            cell4.setCellValue(orderPrice);
//
//            String orderNum = val.get("orderNum").toString();
//            Cell cell5 = row.createCell(5);
//            cell5.setCellStyle(style);
//            cell5.setCellType(Cell.CELL_TYPE_STRING);
//            cell5.setCellValue(orderNum);
//
//            String settlementPrice = val.get("settlementPrice").toString();
//            Cell cell6 = row.createCell(6);
//            cell6.setCellStyle(style);
//            cell6.setCellType(Cell.CELL_TYPE_STRING);
//            cell6.setCellValue(settlementPrice);
//
//
//            String afterSalesPrice = val.get("afterSalesPrice").toString();
//            Cell cell7 = row.createCell(7);
//            cell7.setCellStyle(style);
//            cell7.setCellType(Cell.CELL_TYPE_STRING);
//            cell7.setCellValue(afterSalesPrice);
//
//            String finalPrice = val.get("finalPrice").toString();
//            Cell cell8 = row.createCell(8);
//            cell8.setCellStyle(style);
//            cell8.setCellType(Cell.CELL_TYPE_STRING);
//            cell8.setCellValue(finalPrice);
//
//            net.sf.json.JSONObject list = map.get(goodsName);
//            if (list == null) {
//                map.put(goodsName, val);
//            } else {
//                if (StringUtil.isNotBlank(orderNum)) {
//                    int tmp = StringUtil.isBlank(list.getString("orderNum")) ? 0 : list.getInt("orderNum");
//                    int orderNumInt = tmp + Integer.parseInt(orderNum);
//                    list.put("orderNum", orderNumInt);
//                }
//                if (StringUtil.isNotBlank(settlementPrice)) {
//                    double tmp = StringUtil.isBlank(list.getString("settlementPrice")) ? 0 : list.getDouble("settlementPrice");
//                    double settlementPriceDouble = tmp + Double.parseDouble(settlementPrice);
//                    list.put("settlementPrice", settlementPriceDouble);
//                }
//
//                if (StringUtil.isNotBlank(afterSalesPrice)) {
//                    double tmp = StringUtil.isBlank(list.getString("afterSalesPrice")) ? 0 : list.getDouble("afterSalesPrice");
//                    double afterSalesPriceDouble = tmp + Double.parseDouble(afterSalesPrice);
//                    list.put("afterSalesPrice", afterSalesPriceDouble);
//                }
//
//                if (StringUtil.isNotBlank(finalPrice)) {
//                    try {
//                        double tmp = StringUtil.isBlank(list.getString("finalPrice")) ? 0 : list.getDouble("finalPrice");
//                        double finalPriceDouble = tmp + Double.parseDouble(finalPrice);
//                        list.put("finalPrice", finalPriceDouble);
//                    } catch (Exception e) {
//                        System.out.println(list);
//                    }
//
//                }
//            }
//
//
//        }
//        String[] heards1 = {"商品名称", "结算价格", "购买数量", "结算金额", "售后金额", "最终结算金额"};
//        Sheet sheet1 = this.createSheet(heards1, sheet.getSheetName() + "汇总");
//        int rowIndex1 = sheet1.getLastRowNum();
//        for (String key : map.keySet()) {
//            rowIndex1++;
//            Row row = sheet1.createRow(rowIndex1);
//            Map<String, Object> val = map.get(key);
//
//            String goodsName = val.get("goodsName").toString();
//            Cell cell3 = row.createCell(0);
//            cell3.setCellStyle(style);
//            cell3.setCellType(Cell.CELL_TYPE_STRING);
//            cell3.setCellValue(goodsName);
//
//            String orderPrice = val.get("orderPrice").toString();
//            Cell cell4 = row.createCell(1);
//            cell4.setCellStyle(style);
//            cell4.setCellType(Cell.CELL_TYPE_STRING);
//            cell4.setCellValue(orderPrice);
//
//            String orderNum = val.get("orderNum").toString();
//            Cell cell5 = row.createCell(2);
//            cell5.setCellStyle(style);
//            cell5.setCellType(Cell.CELL_TYPE_STRING);
//            cell5.setCellValue(orderNum);
//
//            String settlementPrice = val.get("settlementPrice").toString();
//            Cell cell6 = row.createCell(3);
//            cell6.setCellStyle(style);
//            cell6.setCellType(Cell.CELL_TYPE_STRING);
//            cell6.setCellValue(settlementPrice);
//
//
//            String afterSalesPrice = val.get("afterSalesPrice").toString();
//            Cell cell7 = row.createCell(4);
//            cell7.setCellStyle(style);
//            cell7.setCellType(Cell.CELL_TYPE_STRING);
//            cell7.setCellValue(afterSalesPrice);
//
//            String finalPrice = val.get("finalPrice").toString();
//            Cell cell8 = row.createCell(5);
//            cell8.setCellStyle(style);
//            cell8.setCellType(Cell.CELL_TYPE_STRING);
//            cell8.setCellValue(finalPrice);
//
//        }
//
//
//    }

    private void convertTeam(List<Map<String, List<Map<String, Object>>>> res) throws Exception {
        //创建样式对象
        CellStyle style = wb.createCellStyle();
        //设置样式对齐方式：水平\垂直居中
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        String[] heards = {"账号", "订单时间", "等级"};

        int rowIndex = sheet.getLastRowNum();
        for (int i = 0; i < res.size(); i++) {
            Map<String, List<Map<String, Object>>> map = res.get(i);
            String sheetName = null;
            List<Map<String, Object>> list = null;
            for (Map.Entry<String, List<Map<String, Object>>> entry : map.entrySet()) {
                sheetName = entry.getKey();
                list = entry.getValue();
            }
            if (i > 0) {
                sheet = this.createSheet(heards, sheetName);
                rowIndex = sheet.getLastRowNum();
            }

            for (int j = 0; j < list.size(); j++) {
                rowIndex++;
                Row row = sheet.createRow(rowIndex);
                Map<String, Object> val = list.get(j);
                String userName = val.get("user_name").toString();
                Cell cell = row.createCell(0);
                cell.setCellStyle(style);
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellValue(userName);

                String createTime = val.get("create_time").toString();
                Cell cell1 = row.createCell(1);
                cell1.setCellStyle(style);
                cell1.setCellType(Cell.CELL_TYPE_STRING);
                cell1.setCellValue(createTime);

                String grade = val.get("grade").toString();
                Cell cell2 = row.createCell(2);
                cell2.setCellStyle(style);
                cell2.setCellType(Cell.CELL_TYPE_STRING);
                cell2.setCellValue(grade);

                System.out.println(list.get(j));
            }


        }

    }


    private void convertOption(List<?> list, List<Map<String, String>> summaryList) throws Exception {
        //创建样式对象
        CellStyle style = wb.createCellStyle();
        //设置样式对齐方式：水平\垂直居中
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        int rowIndex = sheet.getLastRowNum();
        for (int j = 0; j < list.size(); j++) {
            rowIndex++;
            Row row = sheet.createRow(rowIndex);
            Map<String, String> map = (Map<String, String>) list.get(j);
            Map<String, String> oldMap = null;
            if (j > 0) {
                oldMap = (Map<String, String>) list.get(j - 1);
            }
            for (int i = 0; i < 3; i++) {
                String userName = map.get("un" + (i + 1));
                if (null != oldMap) {
                    String userNameOld = oldMap.get("un" + (i + 1));
                    if (userNameOld.equals(userName)) {
                        CellRangeAddress rangeAddress = new CellRangeAddress(j, j + 1, i, i);
                        sheet.addMergedRegion(rangeAddress);
                        if (i == 1) {
                            rangeAddress = new CellRangeAddress(j, j + 1, 3, 3);
                            sheet.addMergedRegion(rangeAddress);
                        }
                    }
                }
                Cell cell = row.createCell(i);
                cell.setCellStyle(style);
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellValue(userName);
            }

            Cell cell1 = row.createCell(3);
            cell1.setCellStyle(style);
            cell1.setCellType(Cell.CELL_TYPE_NUMERIC);
            String teamNum = map.get("teamNum");
            cell1.setCellValue(teamNum);
        }
        String[] heards = {"升级时间", "等级", "用户ID", "邀请人", "一层直邀等级", "实际数量", "二层直邀等级", "实际数量", "用户直邀下级的团队人数"};
        String[] keys = {"levelUpTime", "grade", "userName", "parentUserName", "directGrade", "actualDirectNum", "indirectGrade", "actualIndirectNum", "teamNum"};
        sheet = this.createSheet(heards);
        rowIndex = sheet.getLastRowNum();
        for (int j = 0; j < summaryList.size(); j++) {
            rowIndex++;
            Row row = sheet.createRow(rowIndex);
            Map<String, String> map = summaryList.get(j);
            for (int i = 0; i < keys.length; i++) {
                String key = keys[i];
                String userName = map.get(key);
                Cell cell = row.createCell(i);
                cell.setCellStyle(style);
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellValue(userName);
            }
        }
    }

    */
/**
     * 生成excel表
     *
     * @param filePath, aliyunUpload, sheetTitleMap, headersMap, keysMap, dataMap
     * @return java.lang.String
     * @author 000
     * @Description excelMap
     * @Date 10:07 2019/8/27 0027
     *//*

//    public String excelMap(String filePath, AliyunUpload aliyunUpload, Map<String, String> sheetTitleMap, Map<String, String[]> headersMap
//            , Map<String, String[]> keysMap, Map<String, List<BeanMap>> dataMap) {
//        File file = null;
//        String path = null;
//        try {
//            // 导出数据
//            int i = 0;
//            for (String sheetTitle : sheetTitleMap.keySet()) {
//                sheetMap(headersMap.get(sheetTitle), keysMap.get(sheetTitle), dataMap.get(sheetTitle), sheetTitleMap.get(sheetTitle), i);
//                i++;
//            }
//            // 生成Excel表
//            file = exportFile();
//            InputStream inputStream = new FileInputStream(file);
//            // 上传Excel至阿里云
//            filePath = aliyunUpload.createFolder(bucketName, filePath);
//            path = aliyunUpload.uploadFile(bucketName, "xls", filePath, inputStream);
//            inputStream.close();
//        } catch (Exception e) {
//            logger.error("", e);
//        } finally {
//            if (file != null) {
//                file.delete();
//            }
//        }
//        return path;
//    }

//    private void fillOrderInfo(OrderStatistics addtion, OrderStatistics target) {
//        Class clazz = OrderStatistics.class;
//        Field[] fields = clazz.getDeclaredFields();
//        Method getMethod, setMethod;
//        String fieldName;
//        for (Field field : fields) {
//            fieldName = field.getName();
//            if ("isSplit".equals(fieldName)
//                    || "startTime".equals(fieldName)
//                    || "endTime".equals(fieldName)
//                    || "serialVersionUID".equals(fieldName)
//                    || "orderId".equals(fieldName)
//                    || "parentId".equals(fieldName)) {
//                continue;
//            }
//            PropertyDescriptor pd = null;
//            try {
//                pd = new PropertyDescriptor(field.getName(), OrderStatistics.class);
//            } catch (IntrospectionException e) {
//                e.printStackTrace();
//            }
//            if (pd == null) {
//                return;
//            }
//            getMethod = pd.getReadMethod();
//            setMethod = pd.getWriteMethod();
//            try {
//                Object addtionValue = getMethod.invoke(addtion);
//                if (addtionValue != null) {
//                    if (setMethod.getParameterTypes()[0].getTypeName().equals("long")) {
//                        if (BigDecimal.valueOf(Double.valueOf(addtionValue.toString())).compareTo(BigDecimal.ZERO) != 0) {
//                            setMethod.invoke(target, BigDecimal.valueOf(Double.valueOf(addtionValue.toString())).longValue());
//                        }
//                    } else if (setMethod.getParameterTypes()[0].getTypeName().equals("double")) {
//                        if (BigDecimal.valueOf(Double.valueOf(addtionValue.toString())).compareTo(BigDecimal.ZERO) != 0) {
//                            setMethod.invoke(target, BigDecimal.valueOf(Double.valueOf(addtionValue.toString())).doubleValue());
//                        }
//                    } else if (setMethod.getParameterTypes()[0].getTypeName().equals("java.lang.String")) {
//                        setMethod.invoke(target, addtionValue.toString());
//                    } else if (setMethod.getParameterTypes()[0].getTypeName().equals("java.lang.Integer")) {
//                        if (BigDecimal.valueOf(Double.valueOf(addtionValue.toString())).compareTo(BigDecimal.ZERO) != 0) {
//                            setMethod.invoke(target, BigDecimal.valueOf(Integer.valueOf(addtionValue.toString())).intValue());
//                        }
//                    } else if (setMethod.getParameterTypes()[0].getTypeName().equals("java.math.BigDecimal")) {
//                        if (BigDecimal.valueOf(Double.valueOf(addtionValue.toString())).compareTo(BigDecimal.ZERO) != 0) {
//                            setMethod.invoke(target, BigDecimal.valueOf(Double.valueOf(addtionValue.toString())));
//                        }
//                    }
//                }
//            } catch (IllegalAccessException | InvocationTargetException e) {
//                logger.error(e.getMessage(), e);
//            }
//        }
//    }


    */
/**
     * 创建excel子表
     *
     * @param heards, keys, data, sheetTitle, sheetIndex
     * @return void
     * @author 000
     * @Description sheetMap
     * @Date 10:08 2019/8/27 0027
     *//*

    private void sheetMap(String[] heards, String[] keys, List<BeanMap> data, String sheetTitle, int sheetIndex) {
        //创建样式对象
        CellStyle style = wb.createCellStyle();
        //设置样式对齐方式：水平\垂直居中
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        sheet = this.createSheet(heards);
        wb.setSheetName(sheetIndex, sheetTitle);
        int rowIndex = sheet.getLastRowNum();
        for (int i = 0; i < data.size(); i++) {
            rowIndex++;
            Row row = sheet.createRow(rowIndex);
            Map<String, String> map = data.get(i);
            for (int j = 0; j < keys.length; j++) {
                String key = keys[j];
                String cellVal = String.valueOf(map.get(key));
                Cell cell = row.createCell(j);
                cell.setCellStyle(style);
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellValue(cellVal);
            }
        }
    }

    public File exportFile() {

        String TMP_PATH = System.getProperty("java.io.tmpdir");

        File file = new File(TMP_PATH + "poifiles");
        if (!file.exists()) {
            file.mkdir();
        }

        BufferedOutputStream stream = null;

        // 用时间作为文件名
        long time = System.currentTimeMillis();
        File excelFile = new File(this.exportDir, time + ".xlsx");
        try {
            // 将数据写入Excel文件
            stream = new BufferedOutputStream(new FileOutputStream(excelFile));
            wb.write(stream);
            stream.flush();
            stream.close();
            wb.dispose();
            wb.close();
            return excelFile;
        } catch (Exception e) {
            logger.error("", e);
            return null;
        } finally {
            if (null != stream) {
                stream = null;
            }
            if (null != sheet) {
                sheet = null;
            }
            if (null != wb) {
                wb = null;
            }
        }
    }


}
*/
